package com.spl.seriallibrary.mainserver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.spl.seriallibrary.util.Action;


public class MyBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        // 打开柜门
        if (Action.IOCONTROLLER_OPEN.equals(action)) {
            String lockNum = intent.getExtras().getString("boxid");
            Intent in = new Intent(context, MainServer.class);
            in.putExtra("action", Action.IOCONTROLLER_OPEN_S);
            in.putExtra("boxid", lockNum);
            context.startService(in);
        }
        // 打开多个柜门
        if (Action.IOCONTROLLER_BATCH_OPEN.equals(action)) {
            String[] batchBoxId = intent.getExtras().getStringArray("batchboxid");
            Intent in = new Intent(context, MainServer.class);
            in.putExtra("action", Action.IOCONTROLLER_BATCH_OPEN_S);
            in.putExtra("batchboxid", batchBoxId);
            context.startService(in);
        }
        // 查询多个格口状态
        if (Action.IOCONTROLLER_SIMPLEBATCHQUERY.equals(action)) {
            String[] batchBoxId = intent.getExtras().getStringArray("batchboxid");
            Intent in = new Intent(context, MainServer.class);
            in.putExtra("action", Action.IOCONTROLLER_SIMPLEBATCHQUERY_S);
            in.putExtra("batchboxid", batchBoxId);
            context.startService(in);
        }

        // 查询单隔口
        if (Action.IOCONTROLLER_QUERY.equals(action)) {
            String lockNum = intent.getExtras().getString("boxid");
            Intent in = new Intent(context, MainServer.class);
            in.putExtra("action", Action.IOCONTROLLER_QUERY_S);
            in.putExtra("boxid", lockNum);
            context.startService(in);
        }
        // 重启系统
        if (Action.APP_REBOOT.equals(action)) {
            long time = intent.getExtras().getLong("delayMs");
            Intent in = new Intent(context, MainServer.class);
            in.putExtra("action", Action.APP_REBOOT_S);
            in.putExtra("delayMs", time);
            context.startService(in);
        }
    }
}
